import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React, { useRef, useState } from "react";
import classes from "./share.module.less";
import SecondaryLayout from "../../compoents/secondary-layout";
import useRouter from "../../hooks/useRouter";
import { useDispatch, useSelector } from "react-redux";
import { useTranslation } from "react-i18next";
import { LocalKeyMap } from "../../local";
import { matchTheme, downloadImg, walletRootRef } from "../../utils";
import { useClipboard } from "use-clipboard-copy";
import toast from "../../compoents/toast";
import { QRCodeSVG } from "qrcode.react";
import { useMount } from "ahooks";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
function Share() {
    var _route_location_query;
    var route = useRouter();
    var dispatch = useDispatch();
    var t = useTranslation().t;
    var theme = useSelector(function(rt) {
        return rt.app.theme;
    });
    var qrImageRef = useRef(null);
    var copy = useClipboard({
        onSuccess: function onSuccess() {
            toast.copy();
        }
    }).copy;
    var _useState = _sliced_to_array(useState(((_route_location_query = route.location.query) === null || _route_location_query === void 0 ? void 0 : _route_location_query.NFTinfo) || {}), 1), NFTinfo = _useState[0];
    var copyLink = function() {
        var link = "https://www.ona.social/".concat(NFTinfo.chainType, "/").concat(NFTinfo.contract, "/").concat(NFTinfo.tokenId, "/").concat(NFTinfo.type);
        // const w = window.open(link);
        copy(link);
    };
    var getQRCodeLink = function() {};
    useMount(function() {
        qrImageRef.current = walletRootRef.current.querySelector("#qr");
    });
    return /*#__PURE__*/ _jsxs(_Fragment, {
        children: [
            /*#__PURE__*/ _jsx(SecondaryLayout, {
                title: t(LocalKeyMap.shareNFT),
                backFn: function() {
                    var _route_location_query, _route_location_query1;
                    var query = ((_route_location_query = route.location.query) === null || _route_location_query === void 0 ? void 0 : _route_location_query.from) ? {
                        currentType: (_route_location_query1 = route.location.query) === null || _route_location_query1 === void 0 ? void 0 : _route_location_query1.from
                    } : undefined;
                    dispatch.app.BACK(query);
                },
                children: /*#__PURE__*/ _jsxs("div", {
                    className: classes.share_container,
                    children: [
                        /*#__PURE__*/ _jsx("div", {
                            className: classes.share_img,
                            children: /*#__PURE__*/ _jsx("img", {
                                src: NFTinfo.logoUrl
                            })
                        }),
                        /*#__PURE__*/ _jsxs("div", {
                            className: classes.options,
                            children: [
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.option_item,
                                    onClick: function() {
                                        // return;
                                        try {
                                            downloadImg(NFTinfo.logoUrl, NFTinfo.name, {
                                                url: qrImageRef.current,
                                                type: "svg",
                                                width: 200
                                            }, function() {
                                                toast.createToast({
                                                    type: "errToast",
                                                    message: "image load fail!"
                                                });
                                            });
                                        } catch (err) {
                                            toast.createToast({
                                                type: "errToast",
                                                message: err.toString()
                                            });
                                        }
                                    },
                                    children: [
                                        /*#__PURE__*/ _jsx("div", {
                                            className: classes.option_icon,
                                            children: /*#__PURE__*/ _jsx("img", {
                                                src: matchTheme(theme, {
                                                    light: require("../../assets/icons/save.svg"),
                                                    dark: require("../../assets/icons/dark/save.svg")
                                                })
                                            })
                                        }),
                                        /*#__PURE__*/ _jsx("div", {
                                            className: classes.text,
                                            children: t(LocalKeyMap.savePost)
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ _jsxs("div", {
                                    className: classes.option_item,
                                    onClick: copyLink,
                                    children: [
                                        /*#__PURE__*/ _jsx("div", {
                                            className: classes.option_icon,
                                            children: /*#__PURE__*/ _jsx("img", {
                                                src: matchTheme(theme, {
                                                    light: require("../../assets/icons/shareLink.svg"),
                                                    dark: require("../../assets/icons/dark/shareLink.svg")
                                                })
                                            })
                                        }),
                                        /*#__PURE__*/ _jsx("div", {
                                            className: classes.text,
                                            children: t(LocalKeyMap.copyLink)
                                        })
                                    ]
                                })
                            ]
                        })
                    ]
                })
            }),
            /*#__PURE__*/ _jsx(QRCodeSVG, {
                id: "qr",
                value: "".concat(window.location.protocol, "//").concat(window.location.host, "/").concat(NFTinfo.chainType, "/").concat(NFTinfo.contract, "/").concat(NFTinfo.tokenId),
                fgColor: "#fff",
                bgColor: "transparent",
                style: {
                    visibility: "hidden",
                    position: "absolute",
                    left: -99999
                }
            })
        ]
    });
}
export default Share;

 //# sourceMappingURL=index.js.map